package thomas.studio.spring.security.ldap.service;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RoleMapping {
	
	private static final Pattern REGEX = Pattern.compile("CN=([A-Za-z0-9-]+),.*");
	
	public static final String ROLE_PREFIX = "ROLE_";

	public static Set<String> findRolesForGroup(String group) {
		Set<String> results = new HashSet<String>();
		if(group != null) {
			Matcher m = RoleMapping.REGEX.matcher(group);
			if(m.matches()) {
				results.add(ROLE_PREFIX + m.group(1).toUpperCase());
			}
		}
		return results;
	}
	
	

}
